<?php


namespace App\Admin\Controllers;



use App\Models\House;
use App\Services\RedisFun;
use Dcat\Admin\Http\Controllers\HasResourceActions;

use Illuminate\Http\Request;

class HouseChange
{
    use HasResourceActions;
    public function change($id,Request $request)
    {
        try {
            $data=$request->all()['intermediary_id'];
            $result=House::change($id,$data);
            if($result){
                //存入redis
                $config=[
                    'host'=>'127.0.0.1',
                    'port'=>'6379',
                    'auth'=>''
                ];
                $attr=[];
                $redis=new RedisFun($config,$attr);
                $key='house_'.$id.'_intermediary';
                $redis->set($key,$data);
                return response()->json(['status'=>true,'data'=>['message'=>'指派成功','type'=>"success",'then'=>['action'=>"redirect",'value'=>"http://www.hyzf.com/admin/house"]]]);
            }else{
                return response()->json(['status'=>false,'data'=>['message'=>'指派失败','type'=>"error",'then'=>['action'=>"redirect",'value'=>""]]]);
            }
        } catch (\Exception $e) {
            return response()->json(['status'=>false,'data'=>['message'=>$e->getMessage(),'type'=>"error",'then'=>['action'=>"redirect",'value'=>""]]]);
        }
    }
}
